<html>
<head>
  <title>Sample Password Lost Page</title>
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <script src="https://sdk.amazonaws.com/js/aws-sdk-2.3.7.min.js"></script>
	<script>
  AWS.config.region = '<REGION>';
	AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: '<IDENTITY_POOL_ID>'
  });
  var lambda = new AWS.Lambda();
	</script>
  <h1>Sample Lost Password Page</h1>
  <div id="info">
  Password Lost
  </div>
  <table>
    <tr>
      <td>Email</td>
      <td><input type="email" id="email" size="20">
    </tr>
    <tr>
      <td colspan="2">
        <button id="lost-button">Password Lost</button>
      </td>
    </tr>
		<tr>
      <td colspan="2" class="center">
				<a href="index.html">Back</a>
      </td>
    </tr>
  </table>
  <script>
  var info = document.getElementById('info');
  var email = document.getElementById('email');
  var lostButton = document.getElementById('lost-button');
  lostButton.addEventListener('click', function() {
    info.innerHTML = 'Password Lost...';
		if (email.value == null || email.value == '') {
    	info.innerHTML = 'Please specify your email address.';
		} else {
      var input = {
        email: email.value
      };
      lambda.invoke({
        FunctionName: 'LambdAuthLostPassword',
        Payload: JSON.stringify(input)
      }, function(err, data) {
        if (err) console.log(err, err.stack);
        else {
          var output = JSON.parse(data.Payload);
          if (output.sent) {
            info.innerHTML = 'Email sent. Please check your email to reset your password.';
          } else {
            info.innerHTML = 'Email <b>not</b> sent.';
          }
        }
      });
		}
  });
  </script>
</body>
</html>